package cn.lili.modules.goods.client;

import cn.lili.modules.constant.ServiceConstant;
import cn.lili.modules.goods.entity.dos.Goods;
import cn.lili.modules.goods.entity.dos.GoodsGallery;
import cn.lili.modules.goods.entity.dos.GoodsSku;
import cn.lili.modules.goods.entity.dos.Wholesale;
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
import cn.lili.modules.goods.entity.dto.ProxyGoodsOperationDTO;
import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.goods.fallback.GoodsFallback;
import cn.lili.modules.operationcenter.entity.vos.UrbanStationSearchParams;
import cn.lili.modules.order.order.entity.vo.GoodsSkuMap;
import cn.lili.modules.order.order.entity.vo.warehouse.InterceptReq;
import cn.lili.modules.promotion.entity.vos.BoxMhgoodsVO;
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
import cn.lili.modules.store.entity.dos.Store;
import cn.lili.modules.supplier.entity.dto.SupplierGoodsOperationDTO;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 商品服务client
 *
 * @author Chopper
 * @version v1.0 2021-11-08 09:52
 */
@Service
@FeignClient(path = "${server.servlet.context-path}", name = ServiceConstant.GOODS_SERVICE, contextId = "goods",
        fallback = GoodsFallback.class)
public interface GoodsClient {

    /**
     * 添加商品
     *
     * @param supplierGoodsOperationDTO 商品查询条件
     */
    @PostMapping("/feign/supplierGoods/add")
    void addSupplierGoods(@RequestBody SupplierGoodsOperationDTO supplierGoodsOperationDTO);

    /**
     * 修改商品
     *
     * @param supplierGoodsOperationDTO 商品属性
     */
    @PostMapping("/feign/supplierGoods/edit")
    void editSupplierGoods(@RequestBody SupplierGoodsOperationDTO supplierGoodsOperationDTO);


    /**
     * 修改供应商商品分类
     * @param supplierGoodsOperationDTO
     */
    @PostMapping("/feign/supplierGoods/category/edit")
    void editSupplierGoodsCategory(@RequestBody SupplierGoodsOperationDTO supplierGoodsOperationDTO);


    /**
     * 修改代理商品
     *
     * @param proxyGoodsOperationDTO 代理商品编辑参数
     */
    @PostMapping("/feign/goods/proxy/edit")
    void editProxyGoods(@RequestBody ProxyGoodsOperationDTO proxyGoodsOperationDTO);

    /**
     * 获取商品列表
     *
     * @param goodsSearchParams 商品查询条件
     */
    @PostMapping("/feign/goods/list")
    Page<Goods> queryByParams(@RequestBody GoodsSearchParams goodsSearchParams);

    /**
     * 查询商品VO
     *
     * @param goodsId 商品id
     * @return 商品VO
     */
    @GetMapping("/feign/goods/vo/{goodsId}")
    GoodsVO getGoodsVO(@PathVariable String goodsId);


    /**
     * 获取商品相册
     * @param goodsId
     * @return
     */
    @GetMapping("/feign/goods/gallery/{goodsId}")
    List<GoodsGallery> getGoodsGallery(@PathVariable String goodsId);


    @PostMapping("/feign/goods/gallery/update")
    void updateGoodsGallery(@RequestBody List<GoodsGallery> goodsGalleryList);


    /**
     * 更新商品详情中的图片路径
     */
    @PostMapping("/feign/goods/intro/update")
    void updateGoodsInfoImages(@RequestBody Goods goods);


    /**
     * 更新sku中的图片路径
     * @param skuList
     */
    @PostMapping("/feign/goods/skuimage/update")
    void updateGoodsSkuImages(@RequestBody List<GoodsSku> skuList);



    /**
     * 从缓存中获取商品
     *
     * @param skuId skuid
     * @return 商品详情
     */
    @GetMapping("/feign/goods/sku/{skuId}/cache")
    GoodsSku getGoodsSkuByIdFromCache(@PathVariable String skuId);

    /**
     * 从缓存中获取可参与促销商品
     *
     * @param skuId skuid
     * @return 商品详情
     */
    @GetMapping("/feign/goods/sku/promotion/{skuId}/cache")
    GoodsSku getCanPromotionGoodsSkuByIdFromCache(@PathVariable String skuId);

    /**
     * 批量修改商品信息 以及 sku信息
     *
     * @param store 店铺信息
     */
    //@PutMapping("/feign/goods/update/store")
    @PostMapping("/feign/goods/update/store")
    void updateStoreDetail(@RequestBody Store store);

    /**
     * 批量下架所有店铺商品
     *
     * @param id 店铺id
     */
    @PutMapping("/feign/goods/under/store/{id}")
    void underStoreGoods(@PathVariable String id);

    /**
     * 条件统计商品
     *
     * @param storeId 店铺ID
     * @return 总数
     */
    @GetMapping("/feign/goods/{storeId}/count")
    Long count(@PathVariable String storeId);

    /**
     * 获取sku库存
     *
     * @param skuId skuId
     * @return 库存
     */
    @GetMapping("/feign/goods/sku/{skuId}/stock")
    Integer getStock(@PathVariable String skuId);

    /**
     * 添加商品评价数量
     *
     * @param commentNum 评价数量
     * @param goodsId    商品ID
     */
    @GetMapping("/feign/goods/comment/{goodsId}/num")
    void addGoodsCommentNum(@RequestParam Integer commentNum, @PathVariable String goodsId);

    @GetMapping("/feign/goods/{goodsId}/getById")
    Goods getById(@PathVariable String goodsId);


    @PostMapping("/feign/goods/queryListByParams")
    List<Goods> queryListByParams(@RequestBody GoodsSearchParams searchParams);


    @GetMapping("/feign/goods/{goodsId}/getSkuIdsByGoodsId")
    List<String> getSkuIdsByGoodsId(@PathVariable String goodsId);

    @PostMapping("/feign/goods/sku/list")
    List<GoodsSku> getGoodsSkuByList(@RequestBody GoodsSearchParams searchParams);


    @PutMapping("/feign/goods/buy/{goodsId}/count")
    void updateGoodsBuyCount(@PathVariable String goodsId, @RequestParam int buyCount);

    @GetMapping("/feign/goods/sku/{goodsId}")
    GoodsSku getGoodsSkuById(@PathVariable String goodsId);

    @PutMapping("/feign/goods/goods-sku/updateGoodsSku")
    void updateGoodsSku(@RequestBody GoodsSku goodsSku);

    @PostMapping("/feign/goods/getGoodsByParams")
    Goods getGoodsByParams(@RequestBody GoodsSearchParams searchParams);

    /**
     * 匹配批发规则
     *
     * @param goodsId 商品规则
     * @param num     数量
     * @return 批发规则
     */
    @PostMapping("/feign/goods/wholesale/{goodsId}/match")
    Wholesale getMatchWholesale(@PathVariable String goodsId, @RequestParam Integer num);

    /**
     * 获取批发规则
     *
     * @param goodsId 商品规则
     * @return 批发规则
     */
    @PostMapping("/feign/goods/wholesale/query/{goodsId}")
    List<Wholesale> getWholesale(@PathVariable String goodsId);

    /**
     * 统计sku总数
     *
     * @param storeId 店铺id
     * @return sku总数
     */
    @GetMapping("/feign/goods/sku/countSkuNum/{storeId}")
    Long countSkuNum(@PathVariable String storeId);

    @GetMapping("/feign/goods/sku/countSkuNumByGoods/{storeId}")
    Long countSkuNumByGoods(@PathVariable String storeId);

    /**
     * 商品删除
     *
     * @param goodsIds 批量删除的id集合
     */
    @DeleteMapping("/feign/goods/delete")
    void deleteGoods(@RequestBody List<String> goodsIds);

    /**
     * 商品删除V2
     *
     * @param goodsIds 批量删除的id集合
     */
    @DeleteMapping("/feign/goods/deletev2")
    void deleteGoodsV2(@RequestBody List<String> goodsIds);

    /**
     * 店铺代理供应商商品
     *
     * @param goodsId 商品id
     */
    @PutMapping("/feign/goods/proxy")
    void addSupplierGoods(@RequestParam String goodsId);

    /**
     * 店铺代理供应商商品
     *
     * @param goodsId 商品id
     */
    @PutMapping("/feign/goods/syncStock")
    void syncStock(@RequestBody List<String> goodsId);

    /**
     * 全量更新es索引
     * @param isGreenGoods 是否是绿色商品
     */
    @PostMapping("/feign/goods/index/update")
    void generateFullEs(Integer isGreenGoods);

    @PostMapping("/feign/goods/video/update")
    void updateVideoById(@RequestBody Goods goods);

    /**
     * 根据thirdPartyPlatformId进行修改
     * @return
     */
    @PostMapping("/feign/goods/updateGoods")
    boolean updateGoods(@RequestBody Goods goods);

    @GetMapping("/getByThirdPartyPlatformId")
    List<Goods> getByThirdPartyPlatformId(@RequestParam("productId") String productId);

    @GetMapping("/feign/token")
    String getToken();

    @PostMapping(value = "/feign/goodsSkusConversion")
    public Map<String, List> goodsSkusConversion(@RequestBody GoodsSkuMap goodsSkuMap);

    @PostMapping("/feign/getPlatformGoodsDetail")
    public List<JSONObject> getPlatformGoodsDetail(@RequestBody List<String> goodsIds);
    /**
     * 获取供应商商品列表
     * @param supplierId 供应商ID
     * @param supplierGoodsId 供应商商品ID
     * @return
     */
    @GetMapping("/feign/goods/getProxyGoodsList")
    List<Goods> getProxyGoodsList(@RequestParam("supplierId") String supplierId,@RequestParam("supplierGoodsId") String supplierGoodsId);

    @PostMapping("/feign/addSupplierCategoryPathSon")
    void addSupplierCategoryPathSon(@RequestParam String ids,@RequestParam String categoryPathSon,@RequestParam String categoryPathSonName);


    @PostMapping("/feign/updateById")
    boolean updateById(@RequestBody Goods goods);

    @GetMapping("/feign/addStorage")
    public void addStorage(@RequestParam("id") Integer id);

    @GetMapping("/feign/downGoods")
    public void downGoods(@RequestParam("id") String id);

    @ApiOperation(value = "更新是否全返商品")
    @GetMapping("/feign/goods/updateResultGoods")
    boolean updateResultGoods(@RequestParam("goodsIds") List<String> goodsIds,@RequestParam("isResultGoods") Boolean isResultGoods);

    @GetMapping("/feign/goods/cleanGoodsCache")
    void cleanGoodsCache (@RequestParam List<String> goodsIds);

    @PostMapping("/feign/createGoods")
    boolean createGoods(@RequestBody BoxMhgoodsVO boxMhgoodsVO);

    /**
     * 删除商品
     *
     * @param goodsIds 删除商品集合
     * @param storeId 店铺
     * @return 是否删除
     */
    @GetMapping("/feign/removeGoods")
    boolean removeGoods(@RequestParam("goodsIds") List<String> goodsIds, @RequestParam("storeId") String storeId);

    /**
     * 添加壹邦玖商品到商品库中
     * @param id 第三方平台ID（壹邦玖）
     * @return 是否成功
     */
    @GetMapping("/addGoods")
    boolean addGoods(@RequestParam("id") String id);

    /**
     * 搜索es的sku数据
     * @param goodsId goodsId
     * @return
     */
    @GetMapping("/feign/searchEsByGoodsId")
    Page<EsGoodsIndex> searchEsByGoodsId(@RequestParam String goodsId);

    @PostMapping("/feign/getGoodsCountByStoreIds")
    long getGoodsCountByStoreIds (@RequestBody List<String> storeIds, @RequestParam String marketEnable);

    @PostMapping("/feign/getCurrentMonthGoodsCountByStoreIds")
    long getCurrentMonthGoodsCountByStoreIds (@RequestBody List<String> storeIds);

    @PostMapping("/feign/getGoodsCountByParams")
    long getGoodsCountByParams (@RequestBody UrbanStationSearchParams params);

    @GetMapping("/feign/execute")
    void execute();

    @PostMapping("/feign/sendHttpRequest")
    JSONObject sendHttpRequest(@RequestBody InterceptReq interceptReq);

    @GetMapping("feign/minuteExecute")
    void minuteExecute();


}

